﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BoolanSlide.RedoUndo;
using Configuration;
using Windows.Foundation;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Shapes = Windows.UI.Xaml.Shapes;

namespace BoolanElement
{
    public class BooDiamond:BooTextShapesBase
    {
        Shapes.Polygon diamond;
        public Shapes.Polygon Diamond
        {
            get
            {
                return diamond;
            }
            set
            {
                diamond = value;
            }
        }

        BooDiamondElement diamondElement;
        public BooDiamondElement DiamondElement
        {
            get { return diamondElement; }
        }

        public override BooElement Element
        {
            set { diamondElement = (BooDiamondElement)value; }
            get { return diamondElement; }
        }

        public override BooTextShapesBaseElement TextShapesBaseElement
        {
            get { return diamondElement; }
        }
        
        public override Shapes.Shape Shape
        {
            get { return diamond; }
        }

        public BooDiamond(BooDiamondElement element, SaveForRedoUndo saveForRedoUndo):base(element)
        {
            this.diamondElement = element;
            InitOriginal();
            RedoUndoHelper.SaveStatus(this);
            Focus.InitFocusEvent(this);
        }

        public BooDiamond(BooDiamondElement element)
            : base(element)
        {
            this.diamondElement = element;
            InitOriginalForThumbNails();
        }

        public override void InitShape()
        {
            diamond = new Shapes.Polygon();
            diamond.Points = BooShapesPoints.CopyPointCollection(this.diamondElement.Points);
            diamond.ManipulationMode = ManipulationModes.All;
        }

       
        public override void ReSizeUI(double x, double y)
        {
            if (diamondElement.ElementTransform.Width + x < 50 || diamondElement.ElementTransform.Height + y < 50)
            {
                return;
            }

            diamondElement.ElementTransform.Width = diamondElement.ElementTransform.Width + x;
            diamondElement.ElementTransform.Height = diamondElement.ElementTransform.Height + y;

            diamondElement.PropertyChanged("Shape");
        }

        public override void ApplySize()
        {
            diamondElement.ShapeWidth = diamondElement.ElementTransform.Width;
            diamondElement.ShapeHeight = diamondElement.ElementTransform.Height;

            //this.diamond.Width = diamondElement.ElementTransform.Width;
            //this.diamond.Height = diamondElement.ElementTransform.Height;

            FullGrid.Width = diamondElement.ElementTransform.Width;
            FullGrid.Height = diamondElement.ElementTransform.Height;

            //BooCanvas.Width = diamondElement.ElementTransform.Width;
            //BooCanvas.Height = diamondElement.ElementTransform.Height;

            CenterStack.Width = diamondElement.ElementTransform.Width;
            //CenterStack.MaxHeight = diamondElement.ElementTransform.Height;


            this.TextBox.Width = diamondElement.ElementTransform.Width;
            diamondElement.TextWidth = diamondElement.ElementTransform.Width;
            //this.TextBox.MaxHeight = diamondElement.ElementTransform.Height;
            //diamondElement.TextMaxHeight = diamondElement.ElementTransform.Height;


            Focus.FocusElls.ScopeRectangle.Width = diamondElement.ElementTransform.Width;
            Focus.FocusElls.ScopeRectangle.Height = diamondElement.ElementTransform.Height;
            Focus.SetFocuseEllipseMargin(diamondElement.ElementTransform.Width, diamondElement.ElementTransform.Height);

            Point[] pt = new Point[diamondElement.Points.Count];
            PointCollection pts = new PointCollection();
            diamondElement.Points.CopyTo(pt, 0);
            pt[0].X = diamondElement.ElementTransform.Width * 0.5;
            pt[0].Y = 0;
            pt[1].X = diamondElement.ElementTransform.Width;
            pt[1].Y = diamondElement.ElementTransform.Height / 2;
            pt[2].X = diamondElement.ElementTransform.Width * 0.5;
            pt[2].Y = diamondElement.ElementTransform.Height;
            pt[3].X = 0;
            pt[3].Y = diamondElement.ElementTransform.Height * 0.5;

            pts.Add(pt[0]);
            pts.Add(pt[1]);
            pts.Add(pt[2]);
            pts.Add(pt[3]);

            this.diamond.Points = pts;
            this.diamondElement.Points = pts;
        }

        public override void ReMargin(double x, double y)
        {
            this.Element.ElementTransform.Translate.X += x;
            this.Element.ElementTransform.Translate.Y += y;
        }
    }
}
